﻿using System;
using System.Data;
using System.Configuration;
using System.Web;


namespace CMN.Common.RegExpression
{
    /// <summary>
    ///电子邮件验证
    /// </summary>
    public class EmailRegExpression : RegExpressionBase
    {

        public EmailRegExpression()
            : base(@"\w+([-+.]\w+)*@\w(-.]\w+)*\.\w+([-.]\w+)*") { }

            // @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
    }

    /// <summary>
    /// 汉字验证
    /// </summary>
    public class ChineseRegExpression : RegExpressionBase
    {
        public ChineseRegExpression(): base(@"[\u4e00-\u9fa5]+"){}
    }
    
    /// <summary>
    /// 数字验证
    /// </summary>
    public class NumRegExpression : RegExpressionBase
    {
        public NumRegExpression() : base(@"^\+?[0-9][0-9]*$") { }//@"^([0-9])[0-9]*(\.\w*)?$"
    }

    /// <summary>
    /// 数字和短横杠验证2343__
    /// </summary>
    public class NumAndBarRegExpression : RegExpressionBase
    {
        public NumAndBarRegExpression() : base(@"^\+?[0-9_]*$") { }//@"^([0-9])[0-9]*(\.\w*)?$"
    }
    /// <summary>
    /// 数字和英文字母验证
    /// </summary>
    public class NumAndStringRegExpression : RegExpressionBase
    {
        public NumAndStringRegExpression() : base(@"^[A-Za-z0-9_]+$") { }
    }

    /// <summary>
    /// 数字和英文字符和中文汉字验证
    /// </summary>
    public class NumAndStringAndChineseRegExpression:RegExpressionBase{

        public NumAndStringAndChineseRegExpression() : base(@"^[A-Za-z0-9\u00A1-\u2999\u3001-\uFFFD]+$") { }
    }

    /// <summary>
    /// 自定义验证
    /// </summary>
    public class StringRegExpression:RegExpressionBase{

        public StringRegExpression(string expression) : base(expression) { }
    }

    /// <summary>
    /// 手机号码验证
    /// </summary>
    public class PhoneRegExpression : RegExpressionBase
    {
        public PhoneRegExpression() : base(@"^\d{11}|\d{12}$") { }
    }

    /// <summary>
    /// URL地址验证
    /// </summary>
    public class URLRegExpression : RegExpressionBase
    {
        public URLRegExpression() : base(@"([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*") { }
    }

    public class PostRegExpression:RegExpressionBase {
        public PostRegExpression():base(@"^\d{6}$"){}
    }
    /// <summary>
    /// script标签验证
    /// </summary>
    public class ScriptRegExpression : RegExpressionBase
    {
        public ScriptRegExpression() : base("<[ ]+script[/s/S]+</script *>") { }
    }

    /// <summary>
    /// 超链接中script
    /// </summary>
    public class HrefScriptRegExpression : RegExpressionBase
    {
        public HrefScriptRegExpression() : base(" href *= *[/s/S]*script *:") { }
    }
    /// <summary>
    /// 超链接中连接地址
    /// </summary>
    public class HrefRegExpression : RegExpressionBase
    {
        public HrefRegExpression() : base("href=['|\"]*[^\"|']*['|\"]") { }
    }

    /// <summary>
    /// 事件中script过滤
    /// </summary>
    public class EventScriptRegExpresison : RegExpressionBase
    {
        public EventScriptRegExpresison() : base(" on[/s/S]*=") { }
    }

    /// <summary>
    /// 框架过滤
    /// </summary>
    public class IframeRegExpression : RegExpressionBase
    {
        public IframeRegExpression() : base("<[ ]*iframe[/s/S]+</iframe *>") { }
    }

    /// <summary>
    /// 框架过滤
    /// </summary>
    public class IframesetRegExpression : RegExpressionBase
    {
        public IframesetRegExpression() : base("<frameset[/s/S]+</frameset *>") { }
    }

    /// <summary>
    /// 标签a过滤
    /// </summary>
    public class LinkRegExpression : RegExpressionBase
    {
        public LinkRegExpression() : base("<[ ]*a.+?a[ ]*>") { }
    }

    /// <summary>
    /// 标签image过滤
    /// </summary>
    public class ImageRegExpression : RegExpressionBase
    {
        public ImageRegExpression() : base("<[ ]*[img][^<>]+[ ]*>") { }
    }

    /// <summary>
    /// 检测是否有Sql危险字符
    /// </summary>
    public class SafeSqlStringRegExpression : RegExpressionBase
    {
        public SafeSqlStringRegExpression() : base(@"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']") { }
    }

    /// <summary>
    ///  检测是否有危险的可能用于链接的字符串
    /// </summary>
    public class SafeUserInfoStringRegExpression : RegExpressionBase
    {
        public SafeUserInfoStringRegExpression():base(@"^\s*$|^c:\\con\\con$|[%,\*" + "\"" + @"\s\t\<\>\&]|游客|^Guest"){}
    }

    /// <summary>
    /// 是否时间
    /// </summary>
    public class TimeRegExpression:RegExpressionBase{

        public TimeRegExpression():base(@"^((([0-1]?[0-9])|(2[0-3])):([0-5]?[0-9])(:[0-5]?[0-9])?)$"){}//@"(\d{4})-(\d{1,2})-(\d{1,2})"
    }

    /// <summary>
    /// 是否ip
    /// </summary>
    public class IpRegExpression : RegExpressionBase
    {
        public IpRegExpression() : base(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$") { }
        //@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){2}((2[0-4]\d|25[0-5]|[01]?\d\d?|\*)\.)(2[0-4]\d|25[0-5]|[01]?\d\d?|\*)$"
    }

}
